package com.lucky.back.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.lucky.back.pojo.dto.BannerAddNewDTO;
import com.lucky.back.pojo.vo.BannerListItemVO;
import com.lucky.back.service.IBannerService;
import com.lucky.back.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.UUID;

@Slf4j
@Api(tags = "05.轮播图管理模块")
@RestController
@RequestMapping("/banner")
public class BannerController {
    @Autowired
    IBannerService bannerService;

    @Autowired
    UploadController uploadController;

    private Boolean result;

    // http://localhost:8090/banner/add-new
    @ApiOperation("添加轮播图")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult<Void> addNew(BannerAddNewDTO bannerAddNewDTO)  throws IOException {
        log.debug("图片上传完成!!!!");
        log.debug("开始处理【注册用户】的请求，参数：{}", bannerAddNewDTO);
        bannerService.addNew(bannerAddNewDTO);
        return JsonResult.ok();
    }


    // http://localhost:8080/albums/9527/delete
    @ApiOperation("删除轮播图")
    @ApiOperationSupport(order = 200)
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult<Void> delete(@PathVariable Long id) {
        log.debug("开始处理【删除相册】的请求，参数：{}", id);
        bannerService.delete(id);
        return JsonResult.ok();
    }

    @ApiOperation("查询轮播图列表")
    @ApiOperationSupport(order=420)
    @GetMapping("")
    public JsonResult<List<BannerListItemVO>> list(){
        List<BannerListItemVO> list = bannerService.list();
        return JsonResult.ok(list);
    }
}
